Page({

  /**
   * 页面的初始数据
   */
  data: {
    params:{
      lowCarbonType: 1,
      page: 1,
      size: 10
    },
    list:[]
  },


  goDetail2(){
    wx.showToast({
      title: '已送完',
      icon: 'none'
    })
  },


  goDetail (e) {

    var bookid = e.currentTarget.dataset.bookid
    wx.navigateTo({
      url: '/package/index/pages/bookdetail/bookdetail?bookId=' + bookid,
    })

  },
 goerZhe () {
   wx.navigateTo({
     url: '/package/index/pages/newHuodonger/newHuodonger',
   })
 },

  loadMore() {

    this.data.params.page += 1

    this.getList(this.data.params)
  },


  getType (e) {

    // console.log(e)

    var agetype = e.currentTarget.dataset.agetype

    var agetype2 = "params.lowCarbonType"

    var page = "params.page"

    var size = "params.size"


    this.setData({
      [agetype2]: agetype,
      [page]: 1,
      [size]: 10,
      list: []
    })

    this.getList(this.data.params)

  },

  getList (params) {

    wx.showLoading({
      title: '加载中',
    })
    var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/book/findLowCarbonBook',
      method: 'POST',
      data: params,
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
      },
      success:(res)=>{
        if (res.data.code == 200) {
          wx.hideLoading()


          if (res.data.data.length == 0) {
            wx.showToast({
              title: '加载完毕',
              icon: 'none'
            })


            return
          }

          var list = _this.data.list


          for (var i = 0; i < res.data.data.length; i++) {
            list.push(res.data.data[i])
          }

          _this.setData({
            list: list
          })

        } else {
          wx.hideLoading()
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    var page = "params.page"

    var size = "params.size"

    this.setData({
      [page]: 1,
      [size]: 10,
      list: []
    })
    this.getList(this.data.params)
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})